import 'package:dio/dio.dart';
import 'package:flutter_250303/datas/common_website_data.dart';
import 'package:flutter_250303/datas/home_banner_data.dart';
import 'package:flutter_250303/datas/search_hot_key_data.dart';
import '../datas/home_list_data.dart';
import 'dio_instance.dart';

class Api {
  static Api instance = Api._();

  Api._();

  Future<List<BannerItemData>?> getBanner() async {
    Response response = await DioInstance.instance().get(path: "banner/json");
    // Map<String, dynamic> map = jsonDecode(response.data);
    HomeBannerData bannerData = HomeBannerData.fromJson(response.data);
    return bannerData.bannerList;
  }

  Future<HomeListData?> getHomeList(String pageCount) async {
    Response response = await DioInstance.instance()
        .get(path: "article/list/$pageCount/json", param: {"page_size": 1});
    HomeListData homeData = HomeListData.fromJson(response.data);
    return homeData;
  }
  
  Future<List<CommonWebsiteData>?>getWebsiteList() async {
    Response response = await DioInstance.instance().get(path: "friend/json");
    CommonWebsiteListData webData = CommonWebsiteListData.fromJson(response.data);
    return webData.websiteList;
  }

  Future<List<SearchHotKeyData>?>getHotkeyList() async {
    Response response = await DioInstance.instance().get(path: "hotkey/json");
    SearchHotKeyListData hotkeyData = SearchHotKeyListData.fromJson(response.data);
    return hotkeyData.hotkeyList;
  }
}

